from django.db import models

# Create your models here.
class Category(models.Model):
    #如果不写也会自动帮助我们创建
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=100)
    type = models.IntegerField() #0:导航，1：文章列表，2：内容，3：图片,4：链接类型
    href = models.CharField(max_length=10,null=True,blank=True) #外部的超链接，只有类型为4，值才有意义
    is_nav = models.BooleanField(default=False) #判断栏目是否是导航栏目
    is_index = models.BooleanField(default=False) #判断是否是首页的文章栏目
    create_date = models.DateTimeField()
    parent = models.ForeignKey(to='self',on_delete=models.SET_NULL,null=True,blank=True)

    def __str__(self):
        return f"id:{self.id},{self.name},{self.type},{self.href},{self.is_nav},{self.is_index},{self.create_date},\nparent:{self.parent}"



class Topic(models.Model):
    title = models.CharField(max_length=255)
    content = models.TextField(blank=True,null=True)
    create_date = models.DateTimeField()
    release_date = models.DateTimeField()
    author = models.CharField(max_length=100)
    category = models.ForeignKey(Category,on_delete=models.SET_NULL,null=True,blank=True)